package sysmiddleware

import (
	"github.com/gin-gonic/gin"
	"github.com/vueadmin/app/admin/internal/svc"
	"github.com/vueadmin/app/admin/sys"
	"github.com/vueadmin/app/admin/sys/sysvalidate"
	"github.com/vueadmin/utils"
	"github.com/vueadmin/utils/response"
)

type ActionMiddleware struct {
	svcCtx *svc.ServiceContext
}

func NewActionMiddleware(svcCtx *svc.ServiceContext) *ActionMiddleware {
	return &ActionMiddleware{
		svcCtx: svcCtx,
	}
}

// 创建数据表字段中间件
func (p ActionMiddleware) Handle() gin.HandlerFunc {
	return func(c *gin.Context) {
		var data sys.Action
		if err := utils.BindAndValid(c, &data); err != nil {
			response.Fail(c, err.Error())
			return
		}
		if err := new(sysvalidate.ActionValidate).Validate(&data); err != nil {
			response.Fail(c, err.Error())
			return
		}
		c.Next()
	}
}
